package com.serve.oa.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.serve.oa.dto.BxtDto;
import com.serve.oa.dto.LeaveDto;
import com.serve.oa.dto.LeaveFlowDto;
import com.serve.oa.dto.TaskDto;
import com.serve.oa.entity.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author __tyw
 * @since 2022-12-12
 */
@Repository
public interface TblTaskMapper extends BaseMapper<TblTask> {

    int addyw(TblTask tblTask);

    int addLeave(LeaveDto leaveDto);

    void inlog(TblLog tblLog);


    Page<TaskDto> getMytaskPage(@Param("page") Page<TaskDto> page, @Param("id") Long id);

    @Delete("DELETE FROM tbl_task WHERE task_id = #{id}")
    void delTask( @Param("id") String id);


    @Delete("DELETE FROM tbl_log WHERE task_id = #{id}")
    void dellog( @Param("id") String id);

    @Delete("DELETE FROM tbl_leave WHERE task_id = #{id}")
    void delLeave( @Param("id") String id);

    @Delete("DELETE FROM tbl_bxb WHERE task_id = #{id}")
    void delBxd( @Param("id") String id);

    @Select("SELECT * FROM tbl_leave WHERE task_id = #{id}")
    TtbLeave getLeave(@Param("id") Integer taskId);

    @Select("SELECT * FROM tbl_log WHERE task_id = #{id} ORDER BY time DESC")
    List<TblLog> getLog(Integer taskId);

    Page<TaskDto> myHandleTask(Page<TaskDto> iPage, Long id);

    @Select("SELECT * FROM tbl_task WHERE cur_node != 999")
    List<TaskDto> getNfnList();

    @Select("SELECT s1.id, s1.user_id as user_id ,s1.organ_id as organ_id FROM com_manger_organization s1 LEFT JOIN com_user_organization s2 ON s1.organ_id = s2.organ_id WHERE s2.user_id = #{id}")
    List<ComUserOrganization> getOrg(@Param("id") Integer id);

    @Select("SELECT * FROM com_manger_organization s1  WHERE s1.user_id = #{id} AND s1.organ_id = #{organId}")
    List<Map> getMan(@Param("id")  Long id, @Param("organId")  Integer organId);

    int addbxt(BxtLeave bxtDto);


    @Select("SELECT * FROM tbl_bxb WHERE task_id = #{id}")
    BxtLeave getBxt(Integer taskId);

    @Select("SELECT * FROM article")
    List<Map> listAll();

    int addLeaveFlow(LeaveFlowDto leaveDto);

    Map getqjb(Integer id);
}
